defmodule PhoenixChina.Post do
  use PhoenixChina.Web, :model

  schema "posts" do
    field :title, :string
    field :content, :string
    field :comment_count, :integer

    timestamps

    has_many :comments, PhoenixChina.Comment

    belongs_to :user, PhoenixChina.User
    belongs_to :category, PhoenixChina.Category
  
  end

  @required_fields ~w(title content category_id)
  @optional_fields ~w(comment_count)

  @doc """
  Creates a changeset based on the `model` and `params`.

  If no params are provided, an invalid changeset is returned
  with no validation performed.
  """
  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
  end
end
